package org.mspring.platform.dao.query.convert;

import java.math.BigInteger;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.mspring.platform.dao.query.convert.impl.BigIntegerConverter;
import org.mspring.platform.dao.query.convert.impl.BooleanConverter;
import org.mspring.platform.dao.query.convert.impl.DateConverter;
import org.mspring.platform.dao.query.convert.impl.DefaultConverter;
import org.mspring.platform.dao.query.convert.impl.IntegerConverter;
import org.mspring.platform.dao.query.convert.impl.LongConverter;

/**
 * @author Gao Youbo
 * @since Jan 31, 2012
 */
public class ConverterManager {
    private static final Map<Class<?>, Converter> converters = new HashMap<>();

    static {
        converters.put(Date.class, new DateConverter());
        converters.put(BigInteger.class, new BigIntegerConverter());
        converters.put(Integer.class, new IntegerConverter());
        converters.put(int.class, new IntegerConverter());
        converters.put(Long.class, new LongConverter());
        converters.put(long.class, new LongConverter());
        converters.put(Boolean.class, new BooleanConverter());
        converters.put(boolean.class, new BooleanConverter());
    }

    public static Converter lookup(Class<?> clazz) {
        Converter converter = converters.get(clazz);
        if (converter == null) {
            return new DefaultConverter();
        }
        return converter;
    }
}
